package com.woniu.venue.controller;


import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.PageInfo;
import com.woniu.model.Result;
import com.woniu.venue.dto.coachEnter.CoachEnterDto;
import com.woniu.venue.form.coachEnter.CreatCoachEnterForm;
import com.woniu.venue.form.coachEnter.LoadCoachEnterForCoachForm;
import com.woniu.venue.form.coachEnter.LoadCoachEnterForm;
import com.woniu.venue.form.coachEnter.RefuseCoachEnterForm;
import com.woniu.venue.model.CoachEnter;
import com.woniu.venue.param.coachEnter.CreatCoachEnterParam;
import com.woniu.venue.param.coachEnter.LoadCoachEnterForCoachParam;
import com.woniu.venue.param.coachEnter.LoadCoachEnterParam;
import com.woniu.venue.param.coachEnter.RefuseCoachEnterParam;
import com.woniu.venue.service.CoachEnterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 杜岷芫
 * @since 2024年07月12日
 */

@Api(tags = "教练入驻信息")
@RestController
@RequestMapping("/coachEnter")
public class CoachEnterController {
    @Autowired
    private CoachEnterService coachEnterService;

    /**
     * 生成教练入驻申请
     */
    @PostMapping("/creat")
    @ApiOperation("生成教练入驻申请")
    public Result creat(@RequestBody CreatCoachEnterForm form) {
        CoachEnterDto coachEnterDto = coachEnterService.creat(BeanUtil.toBean(form, CreatCoachEnterParam.class));
        return Result.getResult().setMsg("成功").setData(coachEnterDto);
    }

    /**
     * 通过申请
     */
    @GetMapping("/agree/{id}")
    public Result agree(@PathVariable("id") Integer id) {
        coachEnterService.agree(id);
        return Result.getResult().setMsg("成功");
    }

    /**
     * 拒绝申请
     */

    @PostMapping("/refuse")
    public Result refuse(@RequestBody RefuseCoachEnterForm form) {
        RefuseCoachEnterParam param = BeanUtil.toBean(form, RefuseCoachEnterParam.class);
        coachEnterService.refuse(param);
        return Result.getResult().setMsg("成功");
    }

    /**
     * 取消申请
     */

    @GetMapping("/cancel/{id}")
    public Result cancel(@PathVariable("id") Integer id) {
        coachEnterService.cancel(id);
        return Result.getResult().setMsg("成功");
    }

    /**
     * 加载所有申请
     */
    @PostMapping("/load")
    public Result load(@RequestBody LoadCoachEnterForm form) {
        PageInfo<CoachEnterDto> coachEnterDtoPageInfo= coachEnterService.load(BeanUtil.toBean(form, LoadCoachEnterParam.class));
        return Result.getResult().setMsg("成功").setData(coachEnterDtoPageInfo);
    }

    /**
     * 教练查找自己的入驻申请
     */
    @PostMapping("/findCoachEnterByCoachId")
    public Result findCoachEnterByCoachId(@RequestBody LoadCoachEnterForCoachForm form) {
        PageInfo<CoachEnterDto> coachEnterDtoPageInfo= coachEnterService.findCoachEnterByCoachId(BeanUtil.toBean(form, LoadCoachEnterForCoachParam.class));
        return Result.getResult().setMsg("成功").setData(coachEnterDtoPageInfo);
    }

}

